const orderInfoDao = require('../../dao/orderInfoDao.js');
const winston = require('../../utils/winstonLogger.js');


module.exports = {
    findOrderInfoByCustomerId : findOrderInfoByCustomerId,
    addOrder : addOrder,
    updateorderInfo : updateorderInfo
}



function findOrderInfoByCustomerId(req,res,next){
    // let body = req.body;
    let customerId = req.params.customerId;
    console.log(customerId)
    orderInfoDao.findOrderInfoByCustomerId(customerId,(err,result)=>{
        if(err){
            winston.error(err);
        }else{
            res.json(result);
        }
    });
}


function addOrder(req,res,next){
    let body = req.body;
    var order = {
        merchant : body.merchant,
        customer : body.customer,
        foods : body.foods,
        address : body.address,
        phone : body.phone,
        allTotalMoney:body.allTotalMoney,
        status :'等待商家接单',
        createDate: new Date()
    };
    orderInfoDao.addOrder(order,(err,result)=>{
        if(err){
            winston.error(err);
        }else{
            res.json(result);
        }
    });
}

function updateorderInfo(req,res,next){
    let body = req.body;
    console.log(body);
    orderInfoDao.updateOrderInfo(body,(err,result) =>{
        if(err){
            winston.error(err);
        }else{
            res.json(result);
        }
    });
}